<template>
	<view>
		<!-- 自定义导航栏 -->
	<uni-nav-bar color="#ffffff" background-color="#0A98D5" :status-bar="true" rightText="发布" left-icon="back"  @clickLeft="back"
	@clickRight="submit">
		<view class="u-f-ajc" @tap="changelook">
			{{yinsi}}
		    <view class="icon iconfont icon-xiala "></view>
		</view>
	</uni-nav-bar>
	
	<!-- 下面是多行输入框 -->
	<view class="uni-textarea">
		<textarea v-model="text" value="" placeholder="请输入你的文字"></textarea>
		
	</view>
	
	<!-- 上传图片功能运用uni自带的模板来 -->
	<uploadinage @upload="upload"></uploadinage>
	       <!-- 弹出提醒公告 -->
		<uni-popup id="popupDialog" ref="popupDialog" type="dialog" @change="change">
			<uni-popup-dialog :mask-click="true" :type="msgType" title="温馨提示" content="" :before-close="false" @confirm="dialogConfirm" @close="dialogClose">
				
			</uni-popup-dialog>
		</uni-popup>
	
	</view>
</template>

<script>
	//import message from "../../components/uni-popup/message.js";
	import uniPopupMessage from "../../components/uni-popup/uni-popup-message.vue";
	import uniPopupDialog from '../../components/uni-popup/uni-popup-dialog.vue';
	import uniPopupShare from '../../components/uni-popup/uni-popup-share.vue';
	import uniPopup from "../../components/uni-popup/uni-popup.vue";
	import uploadinage from "../../components/common/uploadimage.vue";
	let changelook=['所有人可见','仅自己可见'];
	
	import uniNavBar from "../../components/uni-nav-bar/uni-nav-bar.vue";
		import uniStatusBar from "../../components/uni-status-bar/uni-status-bar.vue";
	export default {
		components:{
			uniNavBar,
			uniStatusBar,
			uploadinage,
			uniPopup,
			uniPopupMessage,
			uniPopupDialog,
			uniPopupShare
		},
		onReady() {
			// 页面打开自动打开对话框
			// setTimeout(() => {
			// 	this.msgType = 'msgType'
				this.$refs.popupDialog.open();
			// }, 500)
		},
		data() {
			return {
				isgeet:false,
				type: 'top',
				msgType: 'success',
				message: '这是一条成功消息提示',
				value: '默认输入的内容',
				// showpopup:true,
				yinsi:"所有人可见",
				text:"",
				imageList:[]
			}
		},
		onBackPress() {
			//判断用户是否输入文字或有没有上传图片
			if(!this.text&&this.imageList.length<1){return;}
			if(!this.isgeet){
				this.baocun();
				
				return true;
			}
			
			
		},
		
		methods: {
			/*保存为草稿的函数*/
			baocun(){
				uni.showModal({
					content: '是否保存为草稿',
					cancelText: '不保存',
					confirmText: '保存',
					success: res => {
						if(res.confirm){
							console.log("保存")
							
						}else{
							console.log("不保存")
							
						}
						this.isgeet=true;
						uni.navigateBack({
							delta:1
						});
						
					}
					
				});
				},
			/**
			 * 打开基础内容
			 */
			toggle(type) {
				this.type = type
				this.$refs.popup.open()
			},
			/**
			 * 打开消息提示
			 * @param {Object} type
			 */
			toggleMessage(type) {
				this.msgType = type
				switch (type) {
					case 'success':
						this.message = '这是一条成功消息提示'
						break
					case 'warn':
						this.message = '这是一条警告消息提示'
						break
					case 'info':
						this.message = '这是一条消息提示'
						break
					case 'error':
						this.message = '这是一条错误消息提示'
						break
				}
				this.$refs.popupDialog.open()
			},
			/**
			 * 对话框点击确认按钮
			 */
			dialogConfirm(done) {
			uni.hideLoading()
				done()
			},
			/**
			 * 输入对话框的确定事件
			 */
			dialogInputConfirm(done, val) {
				uni.showLoading({
					title: '3秒后会关闭'
				})
				console.log(val);
				this.value = val
				setTimeout(() => {
					uni.hideLoading()
					// 关闭窗口后，恢复默认内容
					done()
				}, 3000)
			},
			/**
			 * 对话框取消按钮
			 */
			dialogClose(done) {
				uni.hideLoading()
				done()
			},
			/**
			 * popup 状态发生变化触发
			 * @param {Object} e
			 */
			change(e) {
				console.log('popup ' + e.type + ' 状态', e.show)
			},
			//返回
			back(){
				uni.navigateBack({
					data:1
				})
				
			},
			//发布
			submit(){
				console.log("fabu")
			},
			//隐私
			changelook(){
				console.log("隐私");
				uni.showActionSheet({
				    itemList: changelook,
				    success:  (res) =>{
						console.log(res.tapIndex)
						switch (res.tapIndex){
							case 0:
							this.yinsi=changelook[res.tapIndex]
							break;
							
							case 1:
							this.yinsi=changelook[res.tapIndex]
							break;
							
						}
						
				       
				    }
				    
				});
			},
			upload(a){
				this.imageList=a;
				console.log(this.imageList);
			}
			
			

		}
	}
</script>

<style>
.u-f-ajc{
	display: flex;
	align-items: center;
	justify-content: center;
	margin-left: 120upx;
}
.uni-textarea{
	/* border: 1upx solid  #EEEEEE; */
	}
	.gonggao{
		width: 500upx;
	}
	.gonggao image{
		width: 75%;
		margin-bottom: 20upx;
	}
	.gonggao button{
		margin-top: 20upx;
		background: #FFE934;
		color: #171606;
	}
</style>
